﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PicACGTool.UserUtils.UserUtils.EX;
using static PicACGTool.UserUtils.UserUtils.EX.DicHelper;
using CatUtils.Utils.SpecialUtils.View;
using PicACGTool.UserUtils.UserView.Winform;

namespace PicACGTool.UserUtils.UserView.Groupbox
{
    public partial class ExAnalysisControl : UserControl
    {
        public ExAnalysisControl()
        {
            InitializeComponent();
            new ViewInfoMemory().InitCheckboxSaveInfo(CbMessageAlert);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UpdataView();
        }

        private void UpdataView()
        {
            listView1.Items.Clear();
            List<DicStruct> DicList = ExAnalysis.Analysis(textBox1.Text);
            Console.WriteLine("CONUNT" + DicList.Count);
            if (DicList.Count == 0)
            {
                MessageHelper.Alert("此文章中的标签在词库中未能找到对应翻译。");
            }
            foreach (var item in DicList)
            {
                ListViewItem lvi = new ListViewItem();

                lvi.Text = item.RomaTag;

                lvi.SubItems.Add(item.Cntag);

                lvi.SubItems.Add(item.Content);

                this.listView1.Items.Add(lvi);
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0) return;

            if (!CbMessageAlert.Checked)
                new MessageAlert(listView1.SelectedItems[0].Text,
                    listView1.SelectedItems[0].SubItems[1].Text,
                    listView1.SelectedItems[0].SubItems[2].Text).ShowDialog();
            else
            {
                Clipboard.SetDataObject(listView1.SelectedItems[0].SubItems[2].Text, true);
                Console.WriteLine($"已复制:{listView1.SelectedItems[0].SubItems[2].Text}{DateTime.Now}");
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
        }

        private void CbMessageAlert_CheckedChanged(object sender, EventArgs e)
        {
            new ViewInfoMemory().SaveCheckboxInfo(CbMessageAlert);
        }
    }
}